{extend name="common/head"/}
<link rel="stylesheet" href="{__ADMIN__}/js/jquery-tagsinput/jquery.tagsinput.min.css">
<link href="{__ADMIN__}/css/style.min.css" rel="stylesheet">
{block name="body"}
<div class="container-fluid p-t-15">

  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">

          <form onsubmit="return false" action="#!" method="post" class="row" id="form1">
            <div class="form-group col-md-12">
              <label for="title">用户名</label>
              <input class="form-control-plaintext" type="text" placeholder="{$admin.username}" readonly value="{$admin.username}">
            </div>
            <div class="form-group col-md-12">
              <label for="title">旧密码</label>
              <input type="password" class="form-control" id="old_pwd" name="old_pwd" value="" placeholder="请输入旧密码" />
            </div>
            <div class="form-group col-md-12">
              <label for="title">新密码</label>
              <input type="password" class="form-control" id="pwd" name="pwd" value="" placeholder="请输入新密码" />
            </div>
            <div class="form-group col-md-12">
              <label for="title">确认新密码</label>
              <input type="password" class="form-control" id="pwd_confirm" name="pwd_confirm" value="" placeholder="请再次输入新密码" />
            </div>
            <div class="form-group col-md-12">
              <button type="submit" class="btn btn-primary ajax-post" target-form="add-form" onclick="add()">确 定</button>
            </div>
          </form>

        </div>
      </div>
    </div>

  </div>

</div>
{/block}
{block name="script"}
{include file="common/footer" base="base" /}

<!--标签插件-->
<script src="{__ADMIN__}/js/jquery-tagsinput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="{__ADMIN__}/js/main.min.js"></script>
<script type="text/javascript">
  function add() {
    $.ajax({
      //几个参数需要注意一下
      type: "POST",//方法类型
      dataType: "json",//预期服务器返回的数据类型
      url: "/admin/api/password_submit" ,//url
      data: $('#form1').serialize(),
      success: function (res) {
        console.log(res);//打印服务端返回的数据(调试用)
        if (res.code === 0) {
          $.alert({
            title: '成功',
            icon: 'mdi mdi-alert',
            type: 'blue',
            content: res.msg,
            buttons: {
              okay: {
                text: '确认',
                btnClass: 'btn-blue',
                action: function() {
                  location.reload();
                }
              }
            }
          });
          // setTimeout(function() {
          //     //	parent.document.location.reload();
          //     parent.document.location.href="{:url('/admin/index')}";
          // }, 1500);
        }else {
          $.alert({
            title: '错误',
            icon: 'mdi mdi-alert',
            type: 'red',
            content: res.msg,
            buttons: {
              okay: {
                text: '确认',
                btnClass: 'btn-blue',
                action: function() {
                  //$('[alt="captcha"]').click();
                }
              }
            }
          });
        };
      },
      error : function() {
        $.alert({
          title: '警告',
          content: '请检查返回是否正常！',
          icon: 'mdi mdi-access-point-network-off',
          animation: 'scale',
          closeAnimation: 'scale',
          buttons: {
            okay: {
              text: '确认',
              btnClass: 'btn-blue'
            }
          }
        });
      }
    });
  }
</script>
{/block}
</body>
</html>